package cn.wolfcode.luowowo.flight.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public  abstract  class DateUtils {

    public static String getWeek(Date date) {
        if (date == null){
            return null;
        }
        String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1 < 0 ? 0 : cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDays[w];
    }

    //分时间
    public static Date getSpecifyTime(Date date, int type){
        switch (type){
            case 1:return getSpecifyDate(date,0,0,0);
            case 2:return getSpecifyDate(date,9,59,0);
            case 3:return getSpecifyDate(date,10,0,0);
            case 4:return getSpecifyDate(date,13,59,0);
            case 5:return getSpecifyDate(date,14,0,0);
            case 6:return getSpecifyDate(date,18,59,0);
            case 7:return getSpecifyDate(date,19,0,0);
            case 8:return getSpecifyDate(date,23,59,50);
            default:return null;
        }

    }

    private static Date getSpecifyDate(Date date,int hour,int min,int sec) {
        if (date == null) {
            return null;
        }
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY,hour);
        c.set(Calendar.MINUTE,min);
        c.set(Calendar.SECOND,sec);
        return c.getTime();
    }

}
